ROOT = .
INCLUDE_DIR = $(ROOT)/Include

export INCLUDE_DIR
#libs value depends on product type
#LIBS := libstu.a  
LIBS := $(LIBS_ENV)

#LIBS := $(subst %:%, % %, $(LIBS_ENV))
CC=gcc
CFLAGS = -I$(INCLUDE_DIR) -Wall -g 

SUBDIRS := $(ROOT)/ModuleA $(ROOT)/ModuleB
SOURCES := $(wildcard *.c)
CHEADERS := $(wildcard *.h)

objects := $(patsubst %.c,%.o,$(wildcard *.c))  




RM = rm -rf

target = main.out


MAKE = make
  
all: $(target)

$(objects) : %.o: %.c
	$(CROSS_COMPILE)gcc -c $(CFLAGS) $< -o $@  

$(target): $(objects)
	for dir in $(SUBDIRS); do $(MAKE) -C $$dir all || exit1; done
	$(CC) $(CFLAGS) $^ -o $@ $(LIBS)

clean:
	@for dir in $(SUBDIRS); do make -C $$dir clean|| exit 1; done
	$(RM) $(objects) $(LIBS) $(target)

.PHONY: all clean 
